#!/bin/sh -ef

# https://travis-ci.com/kaitai-io/kaitai_struct_webide needs to be
# rebuilt after we publish newest JS build of ksc to npm.

PROJECT='kaitai-io/kaitai_struct_webide'
SLUG=$(echo "$PROJECT" | sed 's,/,%2F,g')

echo "Triggering build for $PROJECT project..."
if [ -n "$KAITAI_STRUCT_WEBIDE_TOKEN" ]; then
	body='
	{
		"request": {
			"message": "Build with kaitai-struct-compiler v'"$KAITAI_STRUCT_VERSION"'",
			"branch": "master"
		}
	}
	'

	echo "$body"

	curl -v -fsSL \
		-H "Content-Type: application/json" \
		-H "Accept: application/json" \
		-H "Travis-API-Version: 3" \
		-H "Authorization: token $KAITAI_STRUCT_WEBIDE_TOKEN" \
		-d "$body" \
		"https://api.travis-ci.com/repo/$SLUG/requests"
else
	echo "No KAITAI_STRUCT_WEBIDE_TOKEN found!"
fi
